package com.xyy.saas.payment.cores.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

/**
 * 平安融资审批: ApplyStatus 授信状态
 */
public enum PinganLoanApplyStatusEnum {

    UN_PRE_APPLY("UN_PRE_APPLY", "未预申请"),
    PRE_APPLY_SUCCESS("PRE_APPLY_SUCCESS", "预申请成功"),
    SUBMIT_DENY("SUBMIT_DENY", "提交否决"),
    APPROVING("APPROVING", "审批中"),
    APPROVE_DENY("APPROVE_DENY", "审批否决"),
    APPROVE_PASS("APPROVE_PASS", "审批通过"),
    SIGN_FAILED("SIGN_FAILED", "建额失败"),
    SIGNED_CONT_SUCCESS("SIGNED_CONT_SUCCESS", "已签署合同"),
    INVALID("INVALID", "失效"),
    FREEZE("FREEZE", "冻结"),
    ;

    private String code;
    private String desc;

    private static Map<String, PinganLoanApplyStatusEnum> code2Enum;

    static {
        code2Enum = Arrays.asList(values()).stream().collect(Collectors.toMap(PinganLoanApplyStatusEnum::getCode, UnaryOperator.identity()));
    }

    PinganLoanApplyStatusEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getCodeByXydCreditStatus(String creditStatus) {
        if (XydCreditStatusEnum.FREEZE.getCode().equals(creditStatus)) {
            return FREEZE.code;
        } else if (XydCreditStatusEnum.REFUSE.getCode().equals(creditStatus)) {
            return APPROVE_DENY.code;
        } else {
            return SIGN_FAILED.code;
        }
    }


    public static PinganLoanApplyStatusEnum getEnum(String code) {
        return code2Enum.get(code);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
